def load_csv(filename, delimiter=","):
    with open(filename, "r", encoding="utf-8") as fin:
        data = fin.read().split("\n")[1:]
        data = [line.split(delimiter) for line in data]
    
    return data

def load_txt(filename, delimiter="\t"):
    with open(filename, "r" ,encoding="utf-8") as fin:
        data = fin.read().split("\n")
        data_ = []
        for line in data:
            line = line.split(delimiter)
            line_ = []
            for col in line:
                try:
                    col = eval(col)
                except Exception as e:
                    col = col
                line_.append(col)
            if not line_:
                continue
            if len(line_) == 1:
                data_.append(line_[0])
            else:
                data_.append(line_)
    return data_

def freq_dict2list(freq_dict):
    freq_dict = sorted(freq_dict.items(), key=lambda x:x[1], reverse=True)
    return freq_dict